package com.yidu.qianfeng.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yidu.qianfeng.common.bean.finance.Finance;
import com.yidu.qianfeng.common.bean.finance.FinanceCondition;
import com.yidu.qianfeng.common.util.LayuiJsonWrap;
import com.yidu.qianfeng.service.FinanceServiceInter;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author: 戴超
 * @Description: 收支明细
 */
@Controller
public class FinanceController {
    @Resource(name = "financeServiceImpl")
    private FinanceServiceInter financeService;

    @RequestMapping("/finance")
    public String income(){
        return "finance/finance";
    }

    /**
     *
     * @param page
     * @param limit
     * @return 
     */
    @RequestMapping("/selectAllFinance")
    @ResponseBody
    public Map selectAllFinance(@Param("page")int page, @Param("limit")int limit){
        List<Finance> finances = financeService.selectAllFinance((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",financeService.selectFinanceCount());
        map.put("data",finances);
        return map;
    }
    /**
     * 根据条件查询收支明细
     * @return
     */
    @RequestMapping("/selectFinanceByCondition")
    @ResponseBody
    public LayuiJsonWrap selectFinanceByCondition(@RequestParam("financeCondition")String financeCondition){
        FinanceCondition condition = null;
        try {
            condition = new ObjectMapper().readValue(financeCondition, FinanceCondition.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return financeService.selectFinanceByCondition(condition);
    }

    /**
     * 根据ID个人审核
     * @param ids
     * @return
     */
    @RequestMapping("updatePersonal")
    @ResponseBody
    public String updatePersonal(String[] ids){
        return financeService.updatePersonal(ids);
    }
    /**
     * 根据ID分站审核
     * @param ids
     * @return
     */
    @RequestMapping("updateSubstation")
    @ResponseBody
    public String updateSubstation(String[] ids){
        return financeService.updateSubstation(ids);
    }
}
